package com.mark.web.bill.entity.vo;

import com.mark.common.utils.BigDecimalUtil;
import com.mark.common.utils.DateTimeUtil;
import com.mark.web.bill.entity.dto.GoodsDetail;
import com.mark.web.bill.entity.po.Account;
import com.mark.web.bill.entity.po.Goods;
import com.mark.web.bill.enums.AccountEnum;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @Description: 我的账单vo实体
 * @Author: Mark
 * @CreateDate: 2019/2/3 12:00
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Data
public class AccountVo {

    /**
     * 主键ID
     */
    private Integer id;

    /**
     * 逻辑外键，商品id
     */
    private Integer fkGoodsId;

    /**
     * 加工的零件名称
     */
    private String goodsName;

    /**
     * 加工种类名称
     */
    private String goodsCategoryName;

    /**
     * 加工零件的单价
     */
    private String price;

    /**
     * 加工零件的数量
     */
    private Integer quantity;

    /**
     * 总价,单位是元,保留两位小数
     */
    private String totalPrice;

    /**
     * 账单的描述
     */
    private String description;

    /**
     * 状态：1-未结算,2-已结算
     */
    private String enableStatus;

    /**
     * 加工零件的图片地址
     */
    private String imgAddr;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 创建时间：时间戳
     */
    private Long createTimeValue;

    /**
     * 结算时间
     */
    private String paymentTime;

    public AccountVo(Account account, GoodsDetail goodsDetail){
        this.id = account.getId();
        this.fkGoodsId = account.getFkGoodsId();
        this.goodsName = goodsDetail.getGoodsName();
        this.goodsCategoryName = goodsDetail.getCategoryName();
        this.price = BigDecimalUtil.saveScale2(goodsDetail.getPrice()).toString();
        this.quantity = account.getQuantity();
        this.totalPrice = BigDecimalUtil.saveScale2(account.getTotalPrice()).toString();
        this.description = account.getDescription();
        this.imgAddr = goodsDetail.getImgAddr();
        this.enableStatus = AccountEnum.stateOf(account.getEnableStatus());
        this.createTimeValue = account.getCreateTime().getTime();
        this.createTime = DateTimeUtil.dateToStr2(account.getCreateTime());

        //支持时间的赋值
        String paymentTimeStr = DateTimeUtil.dateToStr2(account.getPaymentTime());
        if(StringUtils.isBlank(paymentTimeStr)) {
            paymentTimeStr = "未定";
        }
        this.paymentTime = paymentTimeStr;

        //描述属性赋值
        String descriptionStr = account.getDescription();
        if(StringUtils.isBlank(descriptionStr)){
            descriptionStr = "无";
        }
        this.description = descriptionStr;
    }

}
